package com.starblink.android.basic.sensorsdata.helper

import com.starblink.android.basic.sensorsdata.room.entity.SkAntEntity
import com.starblink.android.basic.sensorsdata.spm.GTrackerAssistUtils
import com.starblink.android.basic.sensorsdata.spm.cfg.SpmStatisticsDef
import com.starblink.android.basic.sensorsdata.spm.event.TrackEvent
import com.starblink.android.basic.sensorsdata.spm.impl.SpmTrackHandler
import com.starblink.basic.ext.nowTime
import java.io.File

/**
 *  Create by yuanl at 2023/5/8
 **/
class ImgIdentifyTrackHelper {

    private var timeTag = 0L
    private var timeTag2 = 0L

    fun beginUpload() {
        timeTag = nowTime()
    }

    fun endUpload(file: File) {
        SpmTrackHandler.addSingleTrackData(SkAntEntity(
            event = TrackEvent.statistics.value,
            spmCnt = GTrackerAssistUtils.fetchElementValue(0, SpmStatisticsDef.ImageUploadconst),
            params = mapOf(
                "duration" to "${nowTime() - timeTag}",
                "imageSize" to "${file.length()}",
            ),
        ))
    }

    fun beginIdentify() {
        timeTag2 = nowTime()
    }

    fun endIdentify() {
        SpmTrackHandler.addSingleTrackData(SkAntEntity(
            event = TrackEvent.statistics.value,
            spmCnt = GTrackerAssistUtils.fetchElementValue(0, SpmStatisticsDef.ImageRecognizationconst),
            params = mapOf(
                "duration" to "${nowTime() - timeTag2}",
            ),
        ))
    }


}